package com.buba.controller;

import com.buba.service.UserService;
import entity.User;
import entity.VO.UserVO;
import io.swagger.models.auth.In;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import result.CommonResult;
import result.R;
import utils.PasswordManagerUtil;

import javax.websocket.server.PathParam;

/**
 * @author: HeKaiYang
 * @date: 2022年11月21日 19:17
 * @ClassName: LoginController
 * @Description: 用户登录注册模块
 */
@RestController
@RequestMapping("/loginController")
@Log4j2
public class LoginController {

    @Autowired
    UserService userService;
    /**
     *
     * @author: HKY
     * @date: 2022/11/21 20:03
     * @return java.lang.String
     * @Description: 登录
     */
    @RequestMapping("/findUser")
    public CommonResult findUser(@RequestBody User user){
        return userService.selectByPrimaryKey(user);
    }


    /**
     *a
     * @author: HKY
     * @date: 2022/11/22 10:21
     * @param user
     * @return result.R
     * @Description: 注册
     */
    @RequestMapping("/createUser")
    public CommonResult createUser(@RequestBody UserVO user){
        return userService.insert(user);
    }

    /**
     *
     * @author: HKY
     * @date: 2023/2/20 10:14
     * @param phone
     * @return result.R
     * @Description: 给用户手机号发送验证码短信
     */
    @RequestMapping("/sendMobilePhoneVerificationCode")
    public CommonResult sendMobilePhoneVerificationCode(@RequestBody String phone){
        boolean flag = userService.sendMobilePhoneVerificationCode(phone);
        if (flag){
            return CommonResult.ok();
        }else {
            return CommonResult.fail("发送失败");
        }
    }

}